package com.le.tester.book.concurrentjavafight.l_14;

import java.nio.BufferOverflowException;
import java.util.EmptyStackException;

/**
 * createTime：2024/5/14 14:04
 * description：有界缓存的简单实现
 */
public class GrumpyBoundedBuffer<V> extends BaseBoundedBuffer<V> {
    public GrumpyBoundedBuffer(int capacity) {
        super(capacity);
    }

    public synchronized void put(V v) throws BufferOverflowException {
        if (isFull()) {
            throw new BufferOverflowException();
        }
        doPut(v);
    }

    public synchronized V take() throws EmptyStackException {
        if (isEmpty()) {
            throw new EmptyStackException();
        }

        return doTake();
    }
}
